package com.antu.first.web.frontend;

import com.alibaba.fastjson.JSON;
import com.antu.first.bean.Hotel;
import com.antu.first.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/3/10.
 */
@Controller
@RequestMapping("/MobileHotelController")
public class MobileHotelController {

    @Autowired
    private HotelService hotelService;

    @RequestMapping(value = "/gethotelnames", method = RequestMethod.GET)
    @ResponseBody
    public String getHotelNames(){
        Map<String, Object> modelMap = new HashMap<String, Object>();
        try{
            List<Hotel> list = hotelService.selectHotelName();
            if(list.size()<=0){
                modelMap.put("success", false);
                modelMap.put("errMsg", "加载热门搜索失败！");
                return JSON.toJSONString(modelMap);
            }
            modelMap.put("success", true);
            modelMap.put("hotels", list);
        }catch(Exception e){
            modelMap.put("success", false);
            modelMap.put("errMsg", "在获取热搜列表的过程中出现错误！");
        }
        return JSON.toJSONString(modelMap);
    }

}
